<?php
include($_SERVER['DOCUMENT_ROOT'] . "/admin/includes/interceptor.php");
require_once($_SERVER['DOCUMENT_ROOT'] . '/static/db/connect.php');
$sql = " select id,title,outline,date,status from $table_name ORDER BY sort DESC, date DESC ";
$mysqli_result = $mysqli->query($sql);
if ($mysqli_result && $mysqli_result->num_rows > 0) {
    while ($row = $mysqli_result->fetch_assoc()) {
        $rows[] = $row;
    }
}
$mysqli_result->close();
$mysqli->close();
?>
<style>
    .btn-mine {background-color: #ffffff;border-color: #ffffff;color: #000;}
</style>
<div class="row">
    <div class="col-lg-12">
        <section class="panel">
            <header class="panel-heading">
                <?php echo $title_name ?>
                <button type='button' class='btn btn-info btn-mine btn-sm' onclick='add();'><i class='icon-plus'></i></button>
            </header>
            <table class="table table-striped table-advance table-hover table-bordered" id="dataTable">
                <thead>
                <tr>
                    <th class="hidden-phone">ID</th>
                    <th><i class="icon-bullhorn"></i> 标题</th>
                    <th class="hidden-phone"><i class="icon-question-sign"></i> 导语</th>
                    <th class="hidden-phone"><i class="icon-bookmark"></i> 创建时间</th>
                    <th><i class=" icon-edit"></i> 状态</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($rows as $row): ?>
                    <tr class="odd gradeX">
                        <td class="hidden-phone"><?php echo $row['id']; ?></td>
                        <td>
                            <a href="/hush-Inn/skill/be_article.php/<?php echo $row['id']; ?>.tn"><?php echo $row['title']; ?></a>
                        </td>
                        <td class="hidden-phone"><?php echo $row['outline']; ?></td>
                        <td class="center hidden-phone"><?php echo date('m-d. Y', strtotime($row['date'])); ?></td>
                        <td>
                            <?php switch ($row['status']) {
                                case -1:
                                    echo '<span class="label label-default">删除</span>';
                                    break;
                                case 0:
                                    echo '<span class="label label-warning">下架</span>';
                                    break;
                                case 1:
                                    echo '<span class="label label-success">发布</span>';
                                    break;
                                default:
                                    echo '<span class="label label-danger">未知状态</span>';
                            } ?>
                        </td>
                        <td>
                            <?php
                            $row_id = $row['id'];
                            switch ($row['status']) {
                                case 1:
                                    echo '<button class="btn btn-warning btn-xs" art-id="' . $row_id . '"><i class="icon-unlink"></i></button>';
                                    break;
                                default:
                                    echo '<button class="btn btn-success btn-xs"art-id="' . $row_id . '"><i class="icon-ok"></i></button>';
                            } ?>
                            <button class="btn btn-primary btn-xs hidden-phone"><i class="icon-pencil"></i></button>
                            <button class="btn btn-danger btn-xs hidden-phone"
                                    art-id="<?php echo $row_id ?>"><i class="icon-trash"></i>
                            </button>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </section>
    </div>
</div>

<!--新增数据弹框-->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width:80%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    新增数据
                </h4>
            </div>
            <div class="modal-body">
                <iframe id="addData" width="100%" height="715px" frameborder="0"></iframe>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="/admin/static/assets/data-tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="/admin/static/assets/data-tables/DT_bootstrap.js"></script>

<script src="/admin/static/js/dynamic-table.js"></script>